package com.lx.javasunmmrize.factory.simpleFactory.order;

import com.lx.javasunmmrize.factory.simpleFactory.pizza.FruitsPizza;
import com.lx.javasunmmrize.factory.simpleFactory.pizza.PepperPizza;
import com.lx.javasunmmrize.factory.simpleFactory.pizza.Pizza;

/**
 * @Description 将创建pizza对象的方法封装到改工厂类中,如果新增加pizza类,则只用修改改类中方法就可以
 *
 * @Author lx
 * @Date 2021/2/28 17:56
 **/
public class SimpleFactory {


    //简单工厂模式也叫静态工厂模式
    public static Pizza createPizza(String orderType){
        Pizza pizza = null;

        System.out.println("使用简单工厂模式2");
        if (orderType.equals("fruits")) {
            pizza = new FruitsPizza();
            pizza.setName(" 水果披萨 ");
        } else if (orderType.equals("pepper")) {
            pizza = new PepperPizza();
            pizza.setName(" 奶酪披萨 ");
        }
        return pizza;
    }
}
